﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memorandum.Service
{
   public class NavigationService : INavigationService
    {
        private Stack<Uri> goStack = new Stack<Uri>();
        private Stack<Uri> backStack = new Stack<Uri>();
        private Uri temporary = null;
        public bool CanGoBack()
        {
            return goStack.Count > 0;
        }

        public bool CanGoForward()
        {
            return backStack.Count > 0;
        }

    

        public Uri Navigate(string page)
        {
            var uri= new Uri(page, UriKind.Relative);
            goStack.Push(uri);
            return uri;
        }

        public Uri GoBack()
        {
           var uri= goStack.Pop();

           backStack.Push(uri);

           Navigate(uri);
            return uri;
        }

        public Uri GoForward()
        {
            var uri = backStack.Pop();

            goStack.Push(uri);

            return uri;
        }

        public Uri Navigate(Uri uri)
        {
            if (temporary != null)
            {
                goStack.Push(temporary);
            }
            temporary = uri;
            return uri;
        }
    }
}
